<?php

/**
 * ContactUsController is the default controller for this application
 */
class ContactUsController extends CustomControllerBase {
	/**
	 * Constructor of index
	 */
	public function __construct() {
		parent::__construct ();
		// Set page name
		$this->setPageName ( 'contactus' );
		
		// Save urer history which he is visiting
		//$this->userSessionVisitDataService->saveHistoryForCurrentUser(USER_VISIT_CONTACT_US);
		

		// Get SettingsDataService
		$settingsDataService = new SettingsDataService ();
		$this->setPageTitle ( $settingsDataService->getValue ( SETTINGS_CONTACT_TITLE ) );
		$this->setMetaDescription ( $settingsDataService->getValue ( SETTINGS_CONTACT_META_DESCRIPTION ) );
		$this->setMetaKeywords ( $settingsDataService->getValue ( SETTINGS_CONTACT_META_KEYWORDS ) );
	}
	
	/**
	 * The "index" action is the default action for all controllers -- the
	 * landing page of the site.
	 *
	 * @return void
	 *
	 */
	public function indexAction() {
		$actionForm = $this->getPost ( 'actionForm', '' );
		if (! empty ( $actionForm ) && $actionForm == 'submit') {
			$txtFirstName = $this->getPost ( 'name', '' );
			$txtEmail = $this->getPost ( 'email', '' );
			$txtContent = $this->getPost ( 'message', '' );
			
			$settingsDataService = new SettingsDataService ();
			
			$adminEmail = $settingsDataService->getValue ( SETTINGS_ADMIN_EMAIL );
			$adminName = $settingsDataService->getValue ( SETTINGS_ADMIN_NAME );
			
			$message = $txtContent;
			$headers = "";
			
			// SEND MAIL TO ADMINISTRATOR
			$mailer = new MyMailUtils ();
			$mailer->addFrom ( $txtEmail, $txtFirstName );
			$mailer->addTo ( $adminEmail, $adminName );
			
			$emailReplace = array ($adminName, $txtFirstName, $message );
			$contentEmal = SystemEmailDataService::getEmailContent ( SYSTEM_EMAIL_CONTACT_US, $emailReplace );
			$subject = $contentEmal ['subject'];
			$message = $contentEmal ['message'];
			$mailer->send ( $subject, $message );
			$mailer->resetAll ();
			$message = 'Your request has just sent successfully';
		}
		
		if ($this->isMobileMode == false) {
			// Assign Smarty Content
			$this->assignSmartyContent ( 'ContactUs/index.tpl' );
		} else {
			$this->assignSmartyMobileContent ( 'ContactUs/m_index.tpl' );
		}
	}

}
